<?php


namespace App\Http\Controllers\Api;

use App\Businesses\BusinessState;


use Illuminate\Http\Request;
use App\Services\Other\Models\Location;
use Illuminate\Support\Facades\Log;




class LocationController extends BaseController
{

    public function getProvinces()
    {
        $provinces = Location::where('parent_id', 0)->get();
        return $this->successData(compact('provinces'));

    }

    public function getCities(Request $request)
    {
        $provinceId = $request->input('provinceId');
        $province = Location::where('id', $provinceId)->first();
        if (!$province) {
            return $this->success(__('参数有错'));
        }
        $cities = $province->children;
        return $this->successData(compact('cities'));
    }

    public function getDistricts(Request $request)
    {
        $cityId = $request->input('cityId');
        $city = Location::where('id', $cityId)->first();
        if (!$city) {
            return $this->success(__('参数有错'));
        }
        $districts = $city->children;
        return $this->successData(compact('districts'));
    }
    public function getStreets(Request $request)
    {
        $districtId = $request->input('districtId');
        $district = Location::where('id', $districtId)->first();
        if (!$district) {
            return $this->success(__('参数有错'));
        }
        $streets = $district->children;
        return $this->successData(compact('streets'));
    }
}



